define(["jquery"],function($){
  var jieXiMarket = function(){
    // var $market_paiXun = $(".market_paiXun img");
    // var $zongHe = $(".zongHe");
    // $market_paiXun.on("click",function(){
    //   $zongHe.css("display","block")
    // })
    // $(document).on("click",function(){
    //   $zongHe.css("display","none")
    // })
    $.get("../../market.json",function(responseText,responseTatue,responseObj){

      var $products = responseText.data.products;
      console.log($products)


      var $pr1=$products[103532];
      var $pr2=$products[103536];
      var $pr3=$products[103541];
      var $pr4=$products[103549];
      var $pr5=$products[103557];
      var $pr6=$products[103565];
      var $pr7=$products[103569];
      var $pr8=$products[103575];
      var $pr9=$products[103581];
      var $pr10=$products[104747];
      var $pr11=$products[104749];
      var $pr12=$products[104958];

      var arr = [$pr11,$pr10,$pr1,$pr9,$pr2,$pr4,$pr3,$pr5,$pr7,$pr6,$pr8,$pr12]
      console.log(arr)

      $rightLis = responseText.data.products;
      $leftLis = responseText.data.categories;
      console.log($leftLis)
      var $leftUl = $("#mark-left");
      var $rightUl = $('.market_content');

      for(var i=0; i<$leftLis.length; i++){

        $leftName = $leftLis[i].name;
        console.log($leftName);
        var $leftLi = $("<li></li>");
        $leftUl.append($leftLi);
        $leftLi.text($leftName );
      }

      var $li1s = $("#mark-left li");

      console.log($li1s)
      for(var j=0; j<$li1s.length;j++){

        (function(num){
          $($li1s[num]).on("click",function(){
              var $arr1 = arr[num]
            // console.log($arr1)
            $rightUl.empty();
            var $arr1 = arr[num]
            console.log($arr1.length);
            for(var k=0;k<$arr1.length;k++){

                // console.log($arr1[k]);

              var $leftImg = $("<div class='leftImg'></div>");
              var $rightTitle = $("<div class='rightTitle'></div>")
              var $div = $("<div class='apper'></div>")
              // console.log($div.length);
              $div.append($leftImg);
              $div.append($rightTitle);

              var $arrUrl = $arr1[k].img;
              var $arrImg = $("<img>")
              $arrImg.attr("src",$arrUrl);
              $leftImg.append($arrImg);
              var $keywords=$arr1[k].name;
              var $keyP = $("<p class='names'></p>")
              $keyP.text($keywords)
              // console.log($keywords);
              $rightTitle.append($keyP)
              $rightUl.append($div);
                var $val = $("<p class='xuan'></p>");
              if($arr1[k].org_source_value=="1"){

                $val.text("精选");
                $rightTitle.append($val);
                $val.css("color","red");
                  $val.css("border","1px solid red")
              }else{
                  $val.text("1");
                    $rightTitle.append($val);
                    $val.css("color","#fff");
                    $val.css("border","1px solid #fff")

              }
              var $specifics1 = $("<p class='specifics'></p>")
              var $specifics=$arr1[k].specifics;
              $specifics1.text($specifics);
              $rightTitle.append($specifics1);

              var $oldPrice = $arr1[k].d_price;
              var $newPrice = $arr1[k].price;
              var $oldSp =$("<span class='old'></span>");
              var $newSp = $("<span class='news'></span>");
              $newSp.text("￥"+$newPrice);
              if(isNaN($oldPrice)){
                // $oldPrice="";
                $oldSp.text("");
              }else{
                $oldSp.text("￥"+$oldPrice);
              }

              $rightTitle.append($newSp);
              $rightTitle.append($oldSp);

              var $jia = $("<span class='jia'></span>")
              $jia.text("+");
              $rightTitle.append($jia);

            }

          })


        })(j)


      }
      $($li1s[0]).trigger("click");

    })

  }
  return {
    jieXiMarket:jieXiMarket
  }
})
